﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Discussion_Test : System.Web.UI.Page
{
    private int userID;
    protected void Page_Load(object sender, EventArgs e)
    {   
        if (Session["username"] != null)
        {
            username.InnerText = "Signed in as MemeberID = " + Session["username"].ToString();
            userID = Convert.ToInt32(Session["username"].ToString());
        }
        createDummyDiscussionThreads();
    }

    private void createDummyDiscussionThreads()
    {
        int i = 0;
        List<DiscussionThreadsDummy> myThreads = new List<DiscussionThreadsDummy>() { 
            new DiscussionThreadsDummy(){DiscussionID=1, MemberID=1, Text="hi", TimeStamp=DateTime.Now.AddMinutes(i++)},
            new DiscussionThreadsDummy(){DiscussionID=1, MemberID=1, Text="hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi", TimeStamp=DateTime.Now.AddMinutes(i++)},
            new DiscussionThreadsDummy(){DiscussionID=1, MemberID=2, Text="hi there", TimeStamp=DateTime.Now.AddMinutes(i++)},
            new DiscussionThreadsDummy(){DiscussionID=1, MemberID=1, Text="how are you :)", TimeStamp=DateTime.Now.AddMinutes(i++)},
            new DiscussionThreadsDummy(){DiscussionID=1, MemberID=2, Text="i'm fine, how are you!", TimeStamp=DateTime.Now.AddMinutes(i++)},
        };

        DiscussionThreads.DataSource = myThreads;
        DiscussionThreads.DataBind();
    }

    protected void OnItemDataBoundFun(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return;

        DiscussionThreadsDummy thread = e.Item.DataItem as DiscussionThreadsDummy;
        HtmlGenericControl containerDiv = e.Item.FindControl("containerDiv") as HtmlGenericControl;
        HtmlGenericControl baloonDiv = e.Item.FindControl("baloonDiv") as HtmlGenericControl;
        HtmlGenericControl textDiv = e.Item.FindControl("textDiv") as HtmlGenericControl;
        HtmlGenericControl dateDiv = e.Item.FindControl("dateDiv") as HtmlGenericControl;
        if (userID == thread.MemberID)
        {
            baloonDiv.Attributes.Add("class", "hazemDiscussionThreadBaloonThingiSent");
            containerDiv.Attributes.Add("class", containerDiv.Attributes["class"] + " bluebg white");
            textDiv.Attributes.Add("class", textDiv.Attributes["class"] + " white");
            dateDiv.Attributes.Add("class", dateDiv.Attributes["class"] + " white");
        }
        else
        {
            baloonDiv.Attributes.Add("class", "hazemDiscussionThreadBaloonThingiRecieved");
            containerDiv.Attributes.Add("class", containerDiv.Attributes["class"] + " graybg");
        }
    }
}